﻿using MobileBSC_Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MobileBSC_SQLite
{
    public class StrategicGoalReader
    {
        private const string SELECT_STMT =
            "SELECT " +
                 "StrategicGoalID " +
               ", Name " +
               ", Description " +
            "FROM StrategicGoal ";

        public StrategicGoal ReadByID(long id)
        {
            var statement = SELECT_STMT + "WHERE StrategicGoalID = @id;";
            var parameters = new List<SQLiteParameter>();
            parameters.Add(new SQLiteParameter("@id", id));

            return DbTool<StrategicGoal>.ReadSingle(statement, parameters, CreateStrategicGoal);
        }
        public List<StrategicGoal> ReadByPerspective(long perspectiveId)
        {
            var statement = SELECT_STMT + "WHERE PerspectiveID = @id;";
            var parameters = new List<SQLiteParameter>();
            parameters.Add(new SQLiteParameter("@id", perspectiveId));

            return DbTool<StrategicGoal>.ReadMultiple(statement, parameters, CreateStrategicGoal);
        }
        public List<StrategicGoal> ReadAll()
        {
            var statement = SELECT_STMT + ";";

            return DbTool<StrategicGoal>.ReadMultiple(statement, null, CreateStrategicGoal);
        }
        private StrategicGoal CreateStrategicGoal(SQLiteDataReader rd)
        {
            StrategicGoal result = new StrategicGoal();
            result.ID = (long)rd["StrategicGoalID"];
            result.Name = (string)rd["Name"];
            if (rd.IsDBNull(rd.GetOrdinal("Description")))
                result.Description = "";
            else
                result.Description = (string)rd["Description"];

            return result;
        }
    }
}
